/**@file
   DLL for exporting syspy C API. 
   
   @par license 
   Copyright 2012 Lu, Ken. All rights reserved.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 
   @author: Lu, Ken (bluewish.ken.lu@gmail.com)
**/

#include "stdafx.h"
#include <syspy/syspylib.h>
#include <syspy/syspydll.h>

using namespace ken;

DLLAPI
SYSPY_STATUS
SYSPYAPI
syspy_mmio_read(
    u32_t  base, 
    u32_t *length, 
    u8_t  *out
    )
{
    u_assert(length != NULL);
    u_assert(out != NULL);

    u32_t   real = *length;
    u_MmIO  obj;

    u_debug("read mmio: base=0x%x, length=0x%x, output=0x%x", base, *length, out);

    if (*length == 0) {
        u_error("invalid parameter: length should not equal to 0.");
        return SYSPY_INVALID_PARAMETER;
    }

    try{
        obj.read(base, real, out);
    } catch (...) {
        u_error("Fail to read mmio range: 0x%x(0x%x)", base, *length);
        return SYSPY_UNKNOWN;
    }

    *length = real;

    return SYSPY_OK;
}

